<?php
namespace app\serveraddress\service\address;
use \app\manage\service\ApiBase;
use \think\Validate;

class ApiAddress extends ApiBase
{
    protected $addFields = ["pid"=>0, "name"=>"", "py_name"=>"", "zipcode"=>"", "type"=>3, "special"=>0, "order"=>""];
    protected $addressValidate = 'app\serveraddress\validate\Address';
    protected $addressLogic    = '\app\serveraddress\logic\Address';

    // 添加新地区
    public function createAddress()
    {
        $data = $this->receiveData(["pid"=>0, "name"=>"", "py_name"=>"", "zipcode"=>"", "type"=>3, "special"=>0, "order"=>""]);
        return $this->oneStepRun($data, 'serveraddress/address/ApiAddress/createAddress', 'createAddress', '1', $this->addressValidate, $this->addressLogic);
    }

    // 编辑地区信息
    public function editAddress(): array
    {

        $data = $this->issetReceiveData(["id"=>0,"pid"=>0, "name"=>"", "py_name"=>"", "zipcode"=>"", "type"=>3, "special"=>0, "order"=>""]);
        return $this->oneStepRun($data, 'serveraddress/address/ApiAddress/editAddress', 'editAddress', '1', $this->addressValidate, $this->addressLogic);
    }

    // 全部地区列表获取
    public function addressList()
    {
        return $this->oneStepRun([], 'serveraddress/address/ApiAddress/addressList', 'addressList', '1', $this->addressValidate, $this->addressLogic);
    }

    // 某一类地区列表获取
    public function someAddressList()
    {
        $data = $this->receiveData(['pid'=>0]);
        return $this->oneStepRun($data, 'serveraddress/address/ApiAddress/someAddressList', 'someAddressList', '1', $this->addressValidate, $this->addressLogic);
    }
}